import { ListNode } from "@/基本数据结构/SingleLink";

export function isSubPath(
  head: ListNode | null,
  root: TreeNode | null
): boolean {
  if (!head) return true;
  if (!root) return false;
  const isSamePath = (head: ListNode | null, node: TreeNode | null) => {
    if (!head) return true;
    if (!node) return false;
    if (head.val === node.val) {
      return isSamePath(head.next, node.left) || isSamePath(head.next, node.right)
    }
    return false
  };
  if (head.val === root.val) {
    if (isSamePath(head, root)) return true
  }
  return (
    isSubPath(head, root.left) || isSubPath(head, root.right)
  )
}

